<template>
	<view class="work-container">
		<uni-forms class="queryForm" ref="queryForm" :modelValue="queryParams">
			<uni-row>
				<uni-col :span="23">
					<uni-forms-item>
						<uni-data-select v-model="queryParams.type" placeholder="请选择饲料类型"
							:localdata="material_type" @change="handleQuery"></uni-data-select>
					</uni-forms-item>
				</uni-col>
			</uni-row>
			
		</uni-forms>

		<uni-group mode="card" v-for="(item, index) in purchaseList" :index="index" :key="index">
			<view class="code">
				<!-- <text style="font-size:18px">序号：{{index+1}}</text> -->
				<uni-icons class="iconLeft" type="cart" size="30" color="#000000"></uni-icons>
				<uni-icons class="iconRight" type="right" size="15" color="#000000"
						   @click="toPurchaseDetials(item.materiaFeedPurchaseId)"></uni-icons>
			</view>
			<hr/>
			<view class="message">
				<view> 饲料类型：{{item.materiaFeedType}}</view>

				<view v-if="item.materiaFeedStorePosition == 1">
					仓库地址：{{$dict.selectDictLabel('materia_feed_store_position', 1)}} </view>
				<view v-else-if="item.materiaFeedStorePosition ==2">
					仓库地址：{{$dict.selectDictLabel('materia_feed_store_position', 2)}} </view>
				<view v-else-if="item.materiaFeedStorePosition ==3">
					仓库地址：{{$dict.selectDictLabel('materia_feed_store_position', 3)}} </view>
				<view v-else-if="item.materiaFeedStorePosition ==4">
					仓库地址：{{$dict.selectDictLabel('materia_feed_store_position', 4)}} </view>

				<view> 供应商名称：{{item.materiaFeedPurchaseProvider}}</view>
				<view> 数量：{{item.materiaFeedPurchaseNum}}袋</view>
				<view> 单价：{{item.materiaFeedPurchasePrice}}元</view>
				<view> 总价：{{item.materiaFeedPurchaseTotlePrice}}元</view>
				<view> 进货日期：{{item.materiaFeedPurchaseDate}}</view>
			</view>
		</uni-group>
		<!-- 加载更多 -->
		<uni-load-more iconType="auto" :status="status" />
		<!-- 新增加号 -->
		<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" @fabClick="toPurchaseAdd" />
	</view>
</template>

<script>
	import {
		listMaterial,
		addPurchase,
		getPurchase,
		updatePurchase,
		delPurchase,
		getTypes
	} from "@/api/hmy/material";

	export default {
		name: "Purchase",
		//dicts: ['hmy_material_type', 'materia_feed_store_position'],
		data() {
			return {
				
				// 进货表格数据
				purchaseList: [],
				 //饲料类型
				 material_type:[],
				typesList:[],
				//增加的加号
				horizontal: 'right',
				vertical: 'bottom',
				pattern: {
					buttonColor: '#55aa7f',
				},
				//加载更多
				status: 'more',
				total: '',

				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					type: undefined,

				}
			};
		},
		created() {
			this.getTypesList();
			this.getList();
		},
		//上拉加载
		onReachBottom() {
			this.queryParams.pageSize += 5;
			this.getList();
			if (this.purchaseList.length >= this.total) {
				this.status = 'noMore';
				//console.log(this.status);
			} else {
				this.status = 'loading';
			}
		},
		methods: {
			//动态获取饲料数据
			getTypesList(){
			  getTypes().then(res => {
				this.typesList = res.data;
				this.typesList.forEach((item,index) => {
					this.material_type.push({
						'text': item.materiaFeedType,
						'value': item.materiaFeedTypeId
					})
				})
			  })
			},
			/** 查询进货列表 */
			getList() {
				//显示加载框
				uni.showLoading({title: '加载中'});
				listMaterial(this.queryParams).then(response => {
					//console.log(response)
					this.purchaseList = response.rows;
					this.total = response.total;
					this.purchaseList.forEach(purchaseItem => {
						this.typesList.forEach(typeItem => {
						  if (purchaseItem.materiaFeedType == typeItem.materiaFeedTypeId){
							purchaseItem.materiaFeedType = typeItem.materiaFeedType
						  }
						})
					})
					//隐藏加载框
					uni.hideLoading();
				});
			},

			//新增进货加号
			toPurchaseAdd() {
				this.$tab.navigateTo('/pages/hmy/material/purchaseAdd');
			},

			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},

			//详情
			toPurchaseDetials(e) {
				console.log("xiangqing", e)
				this.$tab.navigateTo('/pages/hmy/material/purchaseDetials?id=' + e);
			}




		}
	};
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		min-height: 100%;
		height: auto;
		background-color: #fcfcfc;
	}

	view {
		font-size: 16px;
		line-height: inherit;
	}

	/* #endif */
	.code {
		margin-bottom: 5px;
	}

	.iconleft {
		float: left;
		// margin-right: 10px;
		// margin-top: 5px;
	}

	.iconRight {
		float: right;
		margin-right: 10px;
		margin-top: 5px;
	}

	.message {
		margin-top: 5px;
		color: #838383;
		line-height: 25px;
	}

	.queryForm {
		background-color: #fff;
		//width: 350px;
		margin-top: 8px;
		margin-left: 10px;
	}
</style>
